/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pt.utl.ist.isr.livetrack.ui.propedit;

import java.awt.Component;
import java.beans.PropertyEditorSupport;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.openide.explorer.propertysheet.ExPropertyEditor;
import org.openide.explorer.propertysheet.PropertyEnv;
import pt.utl.ist.isr.livetrack.server.LTServer;
import pt.utl.ist.isr.livetrack.server.interfaces.Zone;
import pt.utl.ist.isr.livetrack.ui.ZoneNode;

/**
 *
 * @author David Miguel Antunes <davidmiguel [ at ] antunes.net>
 */
public class ZoneConnectionsPropertyEditor extends PropertyEditorSupport implements ExPropertyEditor {

    private PropertyEnv pe;

    @Override
    public Component getCustomEditor() {
        return new ZoneConnectionsPropertyEditorPanel(pe);
    }

    @Override
    public boolean supportsCustomEditor() {
        return true;
    }

    @Override
    public String getAsText() {
        LTServer server = ((ZoneNode) pe.getBeans()[0]).getServer();
        Map<String, Zone> zones = server.getPerimeter().getZones();
        String t = "[";
        Iterator<String> it = ((Set<String>) getValue()).iterator();
        if (it.hasNext()) {
            t += zones.get(it.next()).getName();
        }
        while (it.hasNext()) {
            t += ", " + zones.get(it.next()).getName();
        }
        t += "]";
        return t;
    }

    @Override
    public void setAsText(String text) throws IllegalArgumentException {
    }

    @Override
    public void attachEnv(PropertyEnv pe) {
        this.pe = pe;
    }
}
